package com.ijunfu.thread._02_implements_runnable;

import lombok.extern.slf4j.Slf4j;

/**
 *
 * @title  : 创建线程的第二种方式：实现Runnable接口
 *          有三种实现方式：
 *              1. 自定义实现类
 *              2. 匿名内部类
 *              3. Lambda表达式
 * @author : ijunfu <ijunfu@163.com>
 * @date   : 2023/10/23 13:14
 * @version: 1.0
 * @motto  : 位来可期 - 世界很大，我想看看
 *
 */
@Slf4j
public class Main {

    public static void main(String[] args) {
        // 1. 自定义Runnable实现类
        Thread t1 = new Thread(new MyRunnable());

        // 2. 定义匿名内部类
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                log.info("2. my runnable runing...");
            }
        });

        // 3. Lambda表达式
        Thread t3 = new Thread(() -> log.info("3. my runnable runing..."));

        t1.start();
        t2.start();
        t3.start();
    }
}

@Slf4j
class MyRunnable implements Runnable {

    @Override
    public void run() {
      log.info("1. my runnable running...");
    }
}
